﻿using System;
using System.Drawing.Printing;
using System.Windows.Forms;
using Arch.WinForm;
using Pharmacy.Settings.BusinessLayer;

namespace Pharmacy.Windows.Forms
{
    public partial class MiniFormAreaSettings : DevExpress.XtraEditors.XtraForm
    {
        public MiniFormAreaSettings()
        {
            InitializeComponent();
            tb_CompanyName.Text = ServiceFacade.SettingsHelper.DnBrandName;
            tb_OfficeAddress.Text = ServiceFacade.SettingsHelper.DnCompanyAddress;
            tb_SOSTaxCode.Text = ServiceFacade.SettingsHelper.TaxCode;
            tb_SOSClinicAddress.Text = ServiceFacade.SettingsHelper.SOSClinicAddress;
            tb_SOSCompanyName.Text = ServiceFacade.SettingsHelper.SOSCompanyName;
            tb_DNTitleEng.Text = ServiceFacade.SettingsHelper.DnTitleEng;
            tb_DNTitleVn.Text = ServiceFacade.SettingsHelper.DnTitleVn;
            tb_DNVoidTitleEng.Text = ServiceFacade.SettingsHelper.DnVoidTitleEng;
            tb_DNVoidTitleVn.Text = ServiceFacade.SettingsHelper.DnVoidTitleVn;
            tb_DNSerialPrefix.Text = ServiceFacade.SettingsHelper.PrescriptionPrefix;
            tb_CmsDirectory.Text = ServiceFacade.SettingsHelper.CmsDirectory;
            tb_CustomerCopy.Text = ServiceFacade.SettingsHelper.DnCustomerCopy;
            tb_FileCopy.Text = ServiceFacade.SettingsHelper.DnFileCopy;
            tb_PharmacyCopy.Text = ServiceFacade.SettingsHelper.DnPharmacyCopy;
            tb_AccountantCopy.Text = ServiceFacade.SettingsHelper.DnAccountantCopy;
            foreach (String printer in PrinterSettings.InstalledPrinters)
                ddl_LabelPrinter.Items.Add(printer.ToString());
            ApplicationSettings.LoadAppSettings();
            if (!String.IsNullOrEmpty(ApplicationSettings.LabelPrinter))
                ddl_LabelPrinter.SelectedItem = ApplicationSettings.LabelPrinter;
        }
        private void SaveLocalSettings()
        {
            ApplicationSettings.LabelPrinter = ddl_LabelPrinter.SelectedItem.ToString();
            ApplicationSettings.SaveAppSettings();
        }
        private void btn_Save_Click(object sender, EventArgs e)
        {
            ServiceFacade.SettingsHelper.CompanyName = tb_CompanyName.Text;
            ServiceFacade.SettingsHelper.OfficeAddress = tb_OfficeAddress.Text;
            ServiceFacade.SettingsHelper.TaxCode = tb_SOSTaxCode.Text;
            ServiceFacade.SettingsHelper.SOSClinicAddress = tb_SOSClinicAddress.Text;
            ServiceFacade.SettingsHelper.SOSCompanyName = tb_SOSCompanyName.Text; 
            ServiceFacade.SettingsHelper.DnTitleEng = tb_DNTitleEng.Text;
            ServiceFacade.SettingsHelper.DnTitleVn = tb_DNTitleVn.Text;
            ServiceFacade.SettingsHelper.DnVoidTitleEng = tb_DNVoidTitleEng.Text;
            ServiceFacade.SettingsHelper.DnVoidTitleVn = tb_DNVoidTitleVn.Text;
            ServiceFacade.SettingsHelper.PrescriptionPrefix = tb_DNSerialPrefix.Text;
            ServiceFacade.SettingsHelper.CmsDirectory = tb_CmsDirectory.Text;
            ServiceFacade.SettingsHelper.DnCustomerCopy = tb_CustomerCopy.Text;
            ServiceFacade.SettingsHelper.DnPharmacyCopy = tb_PharmacyCopy.Text;
            ServiceFacade.SettingsHelper.DnFileCopy = tb_FileCopy.Text;
            ServiceFacade.SettingsHelper.DnAccountantCopy = tb_AccountantCopy.Text;
            SaveLocalSettings();
            MessageBox.Show("Settings Save Success", "Notice", MessageBoxButtons.OK);

        }
    }
}